package wang.lcs.pay;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayConstants.SignType;

import wang.lcs.pay.config.AlipayConfig;
import wang.lcs.pay.config.WeixinConfig;

@Configuration
public class AppConfig {

    @Bean
    public AlipayClient getClient(AlipayConfig config) {
        return new DefaultAlipayClient(config.getAlipayUrl(), config.getAppId(), config.getPrivateKey(), //
                config.getFormat(), AlipayConfig.UTF_8_CHARSET, config.getAlipayPublicKey(), config.getSignType());
    }

    @Bean
    public WXPay getWeixinClient(WeixinConfig config) {
        return new WXPay(config, SignType.MD5, config.isSandbox());
    }

    @Bean
    public FilterRegistrationBean registration() {
        FilterRegistrationBean filte = new FilterRegistrationBean();
        filte.setFilter(new ErrorLogFilter());
        filte.addUrlPatterns("/*");
        filte.setOrder(1);
        return filte;
    }

}
